<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const arr = [1, 5,2, 3, 4, 4,5,3,5]

        function fn(arr) {
            const nums = [];
            let result = 0;
            let m = 1
            for (const item of arr) {
                
                if (nums.includes(item)) {
                    m--;
                } else {
                    result = item;
                    m++
                };
                m === 0 ? m = 1 : m;
                nums.push(item)
            }

            console.log(result);
            console.log(nums);
            return result
        }
        fn(arr)

    </script>
</body>

</html>